﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Markup;

namespace WPFSLVstoDesigner
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class DesignerManager : Window
    {
        public DesignerManager()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

    
        public void WriteXAML()
        {
        //    // create a writer and open the file
        //    TextWriter tw = new StreamWriter("xaml.xml");

        //    tw.Write(XamlWriter.Save(this.MainGrid));

        //    // close the stream
        //    tw.Close();
            XamlBrowser.Source = null ;
            if(File.Exists("xaml.xml")) 
            {
                File.Delete("xaml.xml");
            }
            File.WriteAllText("xaml.xml", XamlWriter.Save(this.MainGrid));
            Uri uri = new Uri(@"pack://siteoforigin:,,,/xaml.xml", UriKind.Absolute);
            
            XamlBrowser.Source = uri;
            //XamlBrowser.Refresh(false);
        }

        private void tabXaml_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
        {
            
        }

        private void tabXaml_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
          //  WriteXAML();
        }

        private void ViewsRibbon_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //if (tabXaml.IsSelected)
            //{
            //    WriteXAML();
            //}
        }
      
    }
}
